
from AGDefines import *
from AGUtils import *
from AGArea import *
import logging

logger = logging.getLogger(__name__)



class RiChang():

    def __init__(self):
        self.areaDict = {}
        self.LogHeader = __name__
        self.name = __name__

        loadActions(self.name, self.areaDict, RiChangActions)

        logger.info("{} has {} actions".format(self.LogHeader, len(self.areaDict)))


    def CheckRiChang(self,name, enum, img):
        logger.info("{}".format(name))

        if self.areaDict[name].detect(img, enum) < 20:
            click = self.areaDict[name].click
            rect = [click[0] - 10, click[1] - 10, click[0] + 10, click[1] + 10]
            img0 = img[rect[1]:rect[3], rect[0]:rect[2], :]
            #logger.info(img0.shape)
            #cv2.imshow("ric",img0)
            #cv2.waitKey()
            score = checkIsGray(img0)
            logger.info("完成分数检查：" + str(score))
            if score > 50:
                enum.click(click, 600)
                return STATUS_OK
            else:
                return STATUS_FINISHED

        return STATUS_NOTFOUND



gRiChang = RiChang()
